/**
 * Created by lance on 2017/2/26.
 */
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { Jsonp, URLSearchParams,Response } from '@angular/http';
import { Observable }   from 'rxjs/Observable';
import 'rxjs/add/operator/catch';

@Injectable()
export class FeditService {
  constructor(private jsonp: Jsonp) {}

  facedit (facname: string, city:string, web:string, address:string,yhqun:string,checked:string,addresstype:string, catgeryid:string,describe:string,buff:string,
      dimension:string,email:string,phone:string,able:string,situation:string,note:string,log:string,lat:string
  ) {
    let fedit = 'http://api.pinwu.net/site/addfactory';
    let params = new URLSearchParams();
    params.set('facname', facname);     // the user's name
    params.set('city', city);           // the user's repwd
    params.set('web', web);              // the user's repwd
    params.set('address', address);         // the user's email
    params.set('yhqun', yhqun);
    params.set('catgeryid', catgeryid);
    params.set('describe', describe);
    params.set('buff', buff);
    params.set('dimension', dimension);
    params.set('email', email);
    params.set('phonetype', checked);
    params.set('addresstype', addresstype);
    params.set('phone', phone);
    params.set('able', able);
    params.set('situation', situation);
    params.set('note', note);
    params.set('log', log);
    params.set('lat', lat);
    params.set('callback', 'JSONP_CALLBACK');

    return this.jsonp
      .get(fedit, { search: params })
      .map((res:Response)=>{
        let result=res.json();
        console.log(result);
        return result;
      });
  }
   selectdimension(){
    let dimension ='http://api.pinwu.net/site/category';
     let params = new URLSearchParams();
     params.set('callback', 'JSONP_CALLBACK');
     return this.jsonp
       .get(dimension, { search: params })
       .map((res:Response)=>{
         let result=res.json();
         console.log(result);
         return result;
       });
   }

  // private handleError (error: Response | any) {
  //   // In a real world app, we might use a remote logging infrastructure
  //   let errMsg: string;
  //   if (error instanceof Response) {
  //     const body = error.json() || '';
  //     const err = body.error || JSON.stringify(body);
  //     errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
  //   } else {
  //     errMsg = error.message ? error.message : error.toString();
  //   }
  //   console.error(errMsg);
  //   return Observable.throw(errMsg);
  // }
}
